<template>
	<el-form label-width="130px" :model="form" :rules="rules" ref="queryForm">
		<el-row>
			<el-col :span="12">
				<el-form-item label="行政区域" prop="regionId">
					<el-select v-model="form.regionId" size="default" placeholder="请选择"
						style="width: 190px" clearable filterable>
						<el-option v-for="item in options" :key="item.dictValue" :label="item.dictLabel"
							:value="item.dictValue" />
					</el-select>
				</el-form-item>
				<el-form-item label="名称" prop="name">
					<el-input v-model="form.name" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="医院类型" prop="type">
					<!-- <el-input v-model="form.type" style="width: 190px;"></el-input> -->
					<el-select v-model="form.type" size="default" placeholder="请选择" style="width: 190px" clearable
						filterable>
						<el-option v-for="item in typeOptions" :key="item.dictValue" :label="item.dictLabel"
							:value="item.dictLabel" />
					</el-select>

				</el-form-item>
				<el-form-item label="经度" prop="longitude">
					<el-input v-model="form.longitude" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'longitude', 12)"></el-input>
				</el-form-item>
				<el-form-item label="纬度" prop="latitude">
					<el-input v-model="form.latitude" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'latitude', 12)"></el-input>
				</el-form-item>
				<el-form-item label="海拔" prop="elevation">
					<el-input v-model="form.elevation" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'elevation', 2)"></el-input>
				</el-form-item>
				<el-form-item label="详细地址" prop="detailedAddress">
					<el-input v-model="form.detailedAddress" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="联系人" prop="contact">
					<el-input v-model="form.contact" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="联系电话" prop="contactNumber">
					<el-input v-model="form.contactNumber" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'contactNumber', 0)" maxlength="11"></el-input>
				</el-form-item>
				<el-form-item label="医院分级编码" prop="levelCode">
					<el-input v-model="form.levelCode" style="width: 190px;"></el-input>
				</el-form-item>
				<el-form-item label="医院分级" prop="levelName">
					<!-- <el-input v-model="form.levelName" style="width: 190px;"></el-input> -->

					<el-select v-model="form.levelName" size="default" placeholder="请选择" style="width: 190px" clearable
						filterable>
						<el-option v-for="item in fjOptions" :key="item.dictValue" :label="item.dictLabel"
							:value="item.dictLabel" />
					</el-select>

				</el-form-item>
				<el-form-item label="日最大接诊量" prop="maxCount">
					<el-input v-model="form.maxCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'maxCount', 0)"></el-input>
				</el-form-item>

			</el-col>
			<el-col :span="12">

				<el-form-item label="医生数量" prop="ysCount">
					<el-input v-model="form.ysCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'ysCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="护士数量" prop="hshCount">
					<el-input v-model="form.hshCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'hshCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="病床数量" prop="bcCount">
					<el-input v-model="form.bcCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'bcCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="救护车数量" prop="jhcCount">
					<el-input v-model="form.jhcCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'jhcCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="可承担伤员数量" prop="kcdsyCount">
					<el-input v-model="form.kcdsyCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'kcdsyCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="担架数量" prop="djCount">
					<el-input v-model="form.djCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'djCount', 0)"></el-input>
				</el-form-item>

				<el-form-item label="O型血储量" prop="oCount">
					<el-input v-model="form.oCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'oCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="A型血储量" prop="aCount">
					<el-input v-model="form.aCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'aCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="B型血储量" prop="bCount">
					<el-input v-model="form.bCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'bCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="AB型血储量" prop="abCount">
					<el-input v-model="form.abCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'abCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="其他血型储量" prop="otherCount">
					<el-input v-model="form.otherCount" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'otherCount', 0)"></el-input>
				</el-form-item>
				<el-form-item label="特色专科" prop="tszk">
					<el-input v-model="form.tszk" style="width: 190px;"
						@input="e => regOnlyNumSpot(e, form, 'tszk', 0)"></el-input>
				</el-form-item>

			</el-col>
		</el-row>
		<div style="display: flex;justify-content: flex-end;">
			<el-button @click="closethis()" @keyup.prevent @keydown.enter.prevent>取消</el-button>
			<el-button type="primary" @click="submit(queryForm)" @keyup.prevent @keydown.enter.prevent>确定</el-button>
		</div>
	</el-form>
</template>

<script setup>
	import {
		ref,
		reactive,
		onMounted
	} from 'vue'
	import {
		ElMessage
	} from 'element-plus'

	import {
		commonInterface,
		commonMedicalType,
		commonMedicalFj
	} from '@/api/common/common'

	import {
		regOnlyNumSpot
	} from '@/utils/reg'



	const emit = defineEmits(['getList', 'closeWindow'])
	const props = defineProps(['editData', 'options'])

	const form = ref({})

	const queryForm = ref('')

	const typeOptions = ref()
	const fjOptions = ref()
	const options = ref()

	//必填项
	const rules = reactive({})
	//取消
	const closethis = () => {
		emit('closeWindow')
	}

	//确定
	const submit = async (e) => {
		if (!e) return
		await e.validate((valid) => {
			if (valid) {
				let method = 'post'
				if (props.editData) method = 'put'
				commonInterface('/back/renfang/zcbz/hospital/', form.value, method).then(result => {
					if (result.code === 200) {
						ElMessage.success(result.msg)
						emit('closeWindow')
						emit('getList')
					} else {
						ElMessage.error(result.msg)
					}
				})
			}
		})
	}


	const getType = () => {
		commonMedicalType().then(result => {
			if (result.code === 200) typeOptions.value = result.data
		})
	}

	const getFj = () => {
		commonMedicalFj().then(result => {
			if (result.code === 200) fjOptions.value = result.data
		})
	}

	onMounted(() => {
		getType()
		getFj()
		options.value = props.options
		if (props.editData) form.value = props.editData
	})
</script>

<style>
</style>